﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using Northwind.Model;
using System.Diagnostics;

namespace Northwind.Repositories.Entity
{
    public class OrdersRepository : IOrdersRepository
    {
        #region Fields
        private NorthwindContext _context = new NorthwindContext();
        #endregion

        #region IOrdersRepository Members
        public IEnumerable<Order> FindRange(string sortingExpression, int startIndex, int count)
        {
            return _context.Orders
                .Include(o => o.Customer)
                .Include(o => o.Employee)
                .OrderBy(sortingExpression)
                .Skip(startIndex)
                .Take(count);
        }

        public IEnumerable<OrderDetail> FindDetails(int key)
        {
            return _context.OrdersDetails
                .Where(o => o.OrderId == key)
                .Include(o => o.Product);
        }

        public int GetCount()
        {
            return _context.Orders.Count();
        }
        #endregion
    }
}
